﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace SPMetadataFilter.MetadataFilter
{
    [ToolboxItemAttribute(false)]
    public class MetadataFilter : WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/15/SPMetadataFilter/MetadataFilter/MetadataFilterUserControl.ascx";

        protected override void CreateChildControls()
        {
            MetadataFilterUserControl control = (MetadataFilterUserControl)Page.LoadControl(_ascxPath);
            control.WebPartManager = (Microsoft.SharePoint.WebPartPages.SPWebPartManager)this.WebPartManager;
            control.ID = "FilterControl";
            control.TermSet = this.TermSet;
            control.TermStoreGroup = this.TermStoreGroup;
            control.ColumnName = this.ColumnName;
            control.StartingTermId = this.StartingTermId;
            Controls.Add(control);
        }

        [DefaultValue("")]
        [WebDisplayName("Term Store Group")]
        [WebDescription("Type a string value.")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        public string TermStoreGroup { get; set; }

        [DefaultValue("")]
        [WebDisplayName("Term Set")]
        [Description("Type a string value.")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        public string TermSet { get; set; }

        [DefaultValue("")]
        [WebDisplayName("Starting Term Id")]
        [WebDescription("Type a guid value.")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        public string StartingTermId { get; set; }

        [DefaultValue("")]
        [WebDisplayName("Column Name")]
        [WebDescription("Type a string value.")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        public string ColumnName { get; set; }
    }
}
